
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppDakaConfig;
import me.zhengjie.service.AppDakaConfigService;
import me.zhengjie.service.dto.AppDakaConfigQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "考勤规则管理")
@RequestMapping("/api/appDakaConfig")
public class AppDakaConfigController {

    private final AppDakaConfigService appDakaConfigService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appDakaConfig:list')")
    public void exportAppDakaConfig(HttpServletResponse response, AppDakaConfigQueryCriteria criteria) throws IOException {
        appDakaConfigService.download(appDakaConfigService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询考勤规则")
    @ApiOperation("查询考勤规则")
    @PreAuthorize("@el.check('appDakaConfig:list')")
    public ResponseEntity<Object> queryAppDakaConfig(AppDakaConfigQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appDakaConfigService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增考勤规则")
    @ApiOperation("新增考勤规则")
    @PreAuthorize("@el.check('appDakaConfig:add')")
    public ResponseEntity<Object> createAppDakaConfig(@Validated @RequestBody AppDakaConfig resources){
        return new ResponseEntity<>(appDakaConfigService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改考勤规则")
    @ApiOperation("修改考勤规则")
    @PreAuthorize("@el.check('appDakaConfig:edit')")
    public ResponseEntity<Object> updateAppDakaConfig(@Validated @RequestBody AppDakaConfig resources){
        appDakaConfigService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除考勤规则")
    @ApiOperation("删除考勤规则")
    @PreAuthorize("@el.check('appDakaConfig:del')")
    public ResponseEntity<Object> deleteAppDakaConfig(@RequestBody Integer[] ids) {
        appDakaConfigService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}